from flask import Flask
from flask import request,jsonify
import json
import duty_service
import sys

sys.path.append('ai_service')

app = Flask(__name__)

service_handler = duty_service.createDutyService()

@app.route("/")
def hello_redirect():
    return "<p>You can request /jkai !</p>"

@app.route("/jkai")
def hello_jkai():
    return "<p>Hello, Nothing here!</p>"

@app.route("/jkduty/duties", methods=['GET'])
def duty_query():
    req = json.loads(request.data)
    date = req['date']
    limit = req['limit']
    print("date: ", date)
    res_dec = service_handler.query_data(date, limit)
    res = {
        "result":res_dec
    }
    return jsonify(res)

@app.route("/jkduty/duty_parse", methods=['POST'])
def duty_parse():
    req = json.loads(request.data)
    text = req['text']
    result = service_handler.parse_duty(text)
    # save to database
    return result

@app.route("/jkduty/request/feishu_test", methods=['GET'])
def feishu_test():
    service_handler.feishu_test()
    return 'ok'
